package com.marketing.tenant.controller;

import com.marketing.tenant.feign.AuthServiceClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Feign调用测试控制器
 * 用于演示通过Feign客户端调用认证服务
 */
@RestController
@RequestMapping("/test/feign")
public class FeignTestController {

    private static final Logger logger = LoggerFactory.getLogger(FeignTestController.class);

    @Autowired
    private AuthServiceClient authServiceClient;

    /**
     * 测试Feign调用认证服务验证token
     */
    @PostMapping("/verify")
    public ResponseEntity<Map<String, Object>> testFeignVerify(@RequestHeader("Authorization") String authorization) {
        logger.info("开始测试Feign调用认证服务验证token");
        
        try {
            // 通过Feign客户端调用认证服务的verify接口
            ResponseEntity<Map<String, Object>> response = authServiceClient.verifyToken(authorization);
            logger.info("Feign调用认证服务成功，响应状态: {}", response.getStatusCode());
            
            return response;
        } catch (Exception e) {
            logger.error("Feign调用认证服务失败: {}", e.getMessage(), e);
            throw e;
        }
    }
}